<?php

namespace app\api\model;

use think\Model;

/**
 * Travel
 */
class Travel extends Model
{
    // 表名
    protected $name = 'guide_travel';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;



    public function getContentAttr($value): string
    {
        return !$value ? '' : htmlspecialchars_decode($value);
    }


    public function getImageAttr($value){
        return full_url($value);
    }


    public function getGuideTravel(){
        $list = self::where(['status' => 1])->order('weigh desc')
            ->field('id,name,city,image,look_nums,content,create_time')
            ->paginate(10);

        foreach ($list as &$value){
            $value['create_time'] = date("Y.m.d H:i",$value['create_time']);
        }

        return api_message($list);
    }



    public function readGuide($params){
        $type = $params['type'] ?? 1 ;
        $guide_id = $params['guide_id'] ?? 0;

        if($type == 1){
            (new Travel())->where(['id' => $guide_id])->setInc('look_nums');
        }else{
            (new Beginner())->where(['id' => $guide_id])->setInc('look_nums');
        }

        return api_message();
    }


}